{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Finding Games\n",
    "\n",
    "To find a single game, use the `LeagueGameFinder` class.\n",
    "While you can call it without any arguments and get ~30,000 games returned (I believe that's the max number of rows that nba.com will send in a response) across the NBA, WNBA, G-League, and international ball, it's a better idea to pass a team ID.\n",
    "\n",
    "See `nba_api.stats.static.teams` in the [Basics Notebook](Basics.ipynb) for more detail on getting a team ID.\n",
    "\n",
    "Let's try to find the last time the Celtics played the Raptors in 2017-18.\n",
    "That will be four steps:\n",
    "1. Fetch all Celtics games.\n",
    "2. Select just games from the 2017-18 season (SEASON_ID ending in 2017).\n",
    "3. Select games where the opponent is the Raptors (MATCHUP contains 'TOR').\n",
    "4. Order by date and select the last row.\n",
    "\n",
    "And last, we'll also get the play-by-play data from that game."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Get All Celtics Games"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from nba_api.stats.static import teams\n",
    "\n",
    "nba_teams = teams.get_teams()\n",
    "# Select the dictionary for the Celtics, which contains their team ID\n",
    "celtics = [team for team in nba_teams if team['abbreviation'] == 'BOS'][0]\n",
    "celtics_id = celtics['id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SEASON_ID</th>\n",
       "      <th>TEAM_ID</th>\n",
       "      <th>TEAM_ABBREVIATION</th>\n",
       "      <th>TEAM_NAME</th>\n",
       "      <th>GAME_ID</th>\n",
       "      <th>GAME_DATE</th>\n",
       "      <th>MATCHUP</th>\n",
       "      <th>WL</th>\n",
       "      <th>MIN</th>\n",
       "      <th>PTS</th>\n",
       "      <th>...</th>\n",
       "      <th>FT_PCT</th>\n",
       "      <th>OREB</th>\n",
       "      <th>DREB</th>\n",
       "      <th>REB</th>\n",
       "      <th>AST</th>\n",
       "      <th>STL</th>\n",
       "      <th>BLK</th>\n",
       "      <th>TOV</th>\n",
       "      <th>PF</th>\n",
       "      <th>PLUS_MINUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>22018</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021800283</td>\n",
       "      <td>2018-11-24</td>\n",
       "      <td>BOS @ DAL</td>\n",
       "      <td>L</td>\n",
       "      <td>240</td>\n",
       "      <td>104</td>\n",
       "      <td>...</td>\n",
       "      <td>0.923</td>\n",
       "      <td>9</td>\n",
       "      <td>33</td>\n",
       "      <td>42</td>\n",
       "      <td>19</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>21</td>\n",
       "      <td>-9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>22018</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021800268</td>\n",
       "      <td>2018-11-23</td>\n",
       "      <td>BOS @ ATL</td>\n",
       "      <td>W</td>\n",
       "      <td>240</td>\n",
       "      <td>114</td>\n",
       "      <td>...</td>\n",
       "      <td>0.810</td>\n",
       "      <td>7</td>\n",
       "      <td>36</td>\n",
       "      <td>43</td>\n",
       "      <td>31</td>\n",
       "      <td>11</td>\n",
       "      <td>7</td>\n",
       "      <td>16</td>\n",
       "      <td>29</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>22018</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021800255</td>\n",
       "      <td>2018-11-21</td>\n",
       "      <td>BOS vs. NYK</td>\n",
       "      <td>L</td>\n",
       "      <td>241</td>\n",
       "      <td>109</td>\n",
       "      <td>...</td>\n",
       "      <td>0.719</td>\n",
       "      <td>15</td>\n",
       "      <td>35</td>\n",
       "      <td>50</td>\n",
       "      <td>30</td>\n",
       "      <td>10</td>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>16</td>\n",
       "      <td>-8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>22018</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021800239</td>\n",
       "      <td>2018-11-19</td>\n",
       "      <td>BOS @ CHA</td>\n",
       "      <td>L</td>\n",
       "      <td>239</td>\n",
       "      <td>112</td>\n",
       "      <td>...</td>\n",
       "      <td>0.722</td>\n",
       "      <td>8</td>\n",
       "      <td>33</td>\n",
       "      <td>41</td>\n",
       "      <td>31</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>12</td>\n",
       "      <td>22</td>\n",
       "      <td>-5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>22018</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021800229</td>\n",
       "      <td>2018-11-17</td>\n",
       "      <td>BOS vs. UTA</td>\n",
       "      <td>L</td>\n",
       "      <td>240</td>\n",
       "      <td>86</td>\n",
       "      <td>...</td>\n",
       "      <td>0.550</td>\n",
       "      <td>17</td>\n",
       "      <td>34</td>\n",
       "      <td>51</td>\n",
       "      <td>16</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "      <td>14</td>\n",
       "      <td>22</td>\n",
       "      <td>-12.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  SEASON_ID     TEAM_ID TEAM_ABBREVIATION       TEAM_NAME     GAME_ID  \\\n",
       "0     22018  1610612738               BOS  Boston Celtics  0021800283   \n",
       "1     22018  1610612738               BOS  Boston Celtics  0021800268   \n",
       "2     22018  1610612738               BOS  Boston Celtics  0021800255   \n",
       "3     22018  1610612738               BOS  Boston Celtics  0021800239   \n",
       "4     22018  1610612738               BOS  Boston Celtics  0021800229   \n",
       "\n",
       "    GAME_DATE      MATCHUP WL  MIN  PTS     ...      FT_PCT  OREB  DREB  REB  \\\n",
       "0  2018-11-24    BOS @ DAL  L  240  104     ...       0.923     9    33   42   \n",
       "1  2018-11-23    BOS @ ATL  W  240  114     ...       0.810     7    36   43   \n",
       "2  2018-11-21  BOS vs. NYK  L  241  109     ...       0.719    15    35   50   \n",
       "3  2018-11-19    BOS @ CHA  L  239  112     ...       0.722     8    33   41   \n",
       "4  2018-11-17  BOS vs. UTA  L  240   86     ...       0.550    17    34   51   \n",
       "\n",
       "   AST  STL  BLK  TOV  PF  PLUS_MINUS  \n",
       "0   19    8    3   17  21        -9.0  \n",
       "1   31   11    7   16  29        18.0  \n",
       "2   30   10    9    8  16        -8.0  \n",
       "3   31    9    6   12  22        -5.0  \n",
       "4   16   11    4   14  22       -12.0  \n",
       "\n",
       "[5 rows x 28 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from nba_api.stats.endpoints import leaguegamefinder\n",
    "\n",
    "# Query for games where the Celtics were playing\n",
    "gamefinder = leaguegamefinder.LeagueGameFinder(team_id_nullable=celtics_id)\n",
    "# The first DataFrame of those returned is what we want.\n",
    "games = gamefinder.get_data_frames()[0]\n",
    "games.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As you can see above, the season ID is 5 digits.\n",
    "I believe the last 4 will always be the current season (2018 for the 2018-19 season).\n",
    "We can do a sanity check and look at how many games the Celtics have played in recent years."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GAME_ID</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SEASON_ID</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015</th>\n",
       "      <td>103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016</th>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017</th>\n",
       "      <td>113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018</th>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           GAME_ID\n",
       "SEASON_ID         \n",
       "2015           103\n",
       "2016           115\n",
       "2017           113\n",
       "2018            30"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "games.groupby(games.SEASON_ID.str[-4:])[['GAME_ID']].count().loc['2015':]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that some of these games are preseason and summer league, so these numbers aren't just regular season and playoffs."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Filter to Games in the 2017-18 Season"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SEASON_ID</th>\n",
       "      <th>TEAM_ID</th>\n",
       "      <th>TEAM_ABBREVIATION</th>\n",
       "      <th>TEAM_NAME</th>\n",
       "      <th>GAME_ID</th>\n",
       "      <th>GAME_DATE</th>\n",
       "      <th>MATCHUP</th>\n",
       "      <th>WL</th>\n",
       "      <th>MIN</th>\n",
       "      <th>PTS</th>\n",
       "      <th>...</th>\n",
       "      <th>FT_PCT</th>\n",
       "      <th>OREB</th>\n",
       "      <th>DREB</th>\n",
       "      <th>REB</th>\n",
       "      <th>AST</th>\n",
       "      <th>STL</th>\n",
       "      <th>BLK</th>\n",
       "      <th>TOV</th>\n",
       "      <th>PF</th>\n",
       "      <th>PLUS_MINUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>42017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0041700307</td>\n",
       "      <td>2018-05-27</td>\n",
       "      <td>BOS vs. CLE</td>\n",
       "      <td>L</td>\n",
       "      <td>240</td>\n",
       "      <td>79</td>\n",
       "      <td>...</td>\n",
       "      <td>0.737</td>\n",
       "      <td>11</td>\n",
       "      <td>31</td>\n",
       "      <td>42</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>20</td>\n",
       "      <td>-8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>42017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0041700306</td>\n",
       "      <td>2018-05-25</td>\n",
       "      <td>BOS @ CLE</td>\n",
       "      <td>L</td>\n",
       "      <td>241</td>\n",
       "      <td>99</td>\n",
       "      <td>...</td>\n",
       "      <td>0.550</td>\n",
       "      <td>5</td>\n",
       "      <td>26</td>\n",
       "      <td>31</td>\n",
       "      <td>25</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18</td>\n",
       "      <td>-10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>42017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0041700305</td>\n",
       "      <td>2018-05-23</td>\n",
       "      <td>BOS vs. CLE</td>\n",
       "      <td>W</td>\n",
       "      <td>240</td>\n",
       "      <td>96</td>\n",
       "      <td>...</td>\n",
       "      <td>0.913</td>\n",
       "      <td>7</td>\n",
       "      <td>38</td>\n",
       "      <td>45</td>\n",
       "      <td>18</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>19</td>\n",
       "      <td>13.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>42017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0041700304</td>\n",
       "      <td>2018-05-21</td>\n",
       "      <td>BOS @ CLE</td>\n",
       "      <td>L</td>\n",
       "      <td>239</td>\n",
       "      <td>102</td>\n",
       "      <td>...</td>\n",
       "      <td>0.767</td>\n",
       "      <td>9</td>\n",
       "      <td>28</td>\n",
       "      <td>37</td>\n",
       "      <td>21</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>26</td>\n",
       "      <td>-9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>42017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0041700303</td>\n",
       "      <td>2018-05-19</td>\n",
       "      <td>BOS @ CLE</td>\n",
       "      <td>L</td>\n",
       "      <td>240</td>\n",
       "      <td>86</td>\n",
       "      <td>...</td>\n",
       "      <td>0.786</td>\n",
       "      <td>6</td>\n",
       "      <td>28</td>\n",
       "      <td>34</td>\n",
       "      <td>16</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>15</td>\n",
       "      <td>25</td>\n",
       "      <td>-30.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   SEASON_ID     TEAM_ID TEAM_ABBREVIATION       TEAM_NAME     GAME_ID  \\\n",
       "30     42017  1610612738               BOS  Boston Celtics  0041700307   \n",
       "31     42017  1610612738               BOS  Boston Celtics  0041700306   \n",
       "32     42017  1610612738               BOS  Boston Celtics  0041700305   \n",
       "33     42017  1610612738               BOS  Boston Celtics  0041700304   \n",
       "34     42017  1610612738               BOS  Boston Celtics  0041700303   \n",
       "\n",
       "     GAME_DATE      MATCHUP WL  MIN  PTS     ...      FT_PCT  OREB  DREB  REB  \\\n",
       "30  2018-05-27  BOS vs. CLE  L  240   79     ...       0.737    11    31   42   \n",
       "31  2018-05-25    BOS @ CLE  L  241   99     ...       0.550     5    26   31   \n",
       "32  2018-05-23  BOS vs. CLE  W  240   96     ...       0.913     7    38   45   \n",
       "33  2018-05-21    BOS @ CLE  L  239  102     ...       0.767     9    28   37   \n",
       "34  2018-05-19    BOS @ CLE  L  240   86     ...       0.786     6    28   34   \n",
       "\n",
       "    AST  STL  BLK  TOV  PF  PLUS_MINUS  \n",
       "30   18    6    0    5  20        -8.0  \n",
       "31   25    5    2   13  18       -10.0  \n",
       "32   18   10    6    8  19        13.0  \n",
       "33   21    9    3    9  26        -9.0  \n",
       "34   16    4    4   15  25       -30.0  \n",
       "\n",
       "[5 rows x 28 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Subset the games to when the last 4 digits of SEASON_ID were 2017.\n",
    "games_1718 = games[games.SEASON_ID.str[-4:] == '2017']\n",
    "games_1718.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Filter to Games Against the Raptors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SEASON_ID</th>\n",
       "      <th>TEAM_ID</th>\n",
       "      <th>TEAM_ABBREVIATION</th>\n",
       "      <th>TEAM_NAME</th>\n",
       "      <th>GAME_ID</th>\n",
       "      <th>GAME_DATE</th>\n",
       "      <th>MATCHUP</th>\n",
       "      <th>WL</th>\n",
       "      <th>MIN</th>\n",
       "      <th>PTS</th>\n",
       "      <th>...</th>\n",
       "      <th>FT_PCT</th>\n",
       "      <th>OREB</th>\n",
       "      <th>DREB</th>\n",
       "      <th>REB</th>\n",
       "      <th>AST</th>\n",
       "      <th>STL</th>\n",
       "      <th>BLK</th>\n",
       "      <th>TOV</th>\n",
       "      <th>PF</th>\n",
       "      <th>PLUS_MINUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021701171</td>\n",
       "      <td>2018-04-04</td>\n",
       "      <td>BOS @ TOR</td>\n",
       "      <td>L</td>\n",
       "      <td>237</td>\n",
       "      <td>78</td>\n",
       "      <td>...</td>\n",
       "      <td>0.893</td>\n",
       "      <td>8</td>\n",
       "      <td>35</td>\n",
       "      <td>43</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>-18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021701140</td>\n",
       "      <td>2018-03-31</td>\n",
       "      <td>BOS vs. TOR</td>\n",
       "      <td>W</td>\n",
       "      <td>240</td>\n",
       "      <td>110</td>\n",
       "      <td>...</td>\n",
       "      <td>0.852</td>\n",
       "      <td>8</td>\n",
       "      <td>33</td>\n",
       "      <td>41</td>\n",
       "      <td>19</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>23</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021700798</td>\n",
       "      <td>2018-02-06</td>\n",
       "      <td>BOS @ TOR</td>\n",
       "      <td>L</td>\n",
       "      <td>240</td>\n",
       "      <td>91</td>\n",
       "      <td>...</td>\n",
       "      <td>0.750</td>\n",
       "      <td>9</td>\n",
       "      <td>29</td>\n",
       "      <td>38</td>\n",
       "      <td>21</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>17</td>\n",
       "      <td>19</td>\n",
       "      <td>-20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>117</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021700188</td>\n",
       "      <td>2017-11-12</td>\n",
       "      <td>BOS vs. TOR</td>\n",
       "      <td>W</td>\n",
       "      <td>239</td>\n",
       "      <td>95</td>\n",
       "      <td>...</td>\n",
       "      <td>0.789</td>\n",
       "      <td>15</td>\n",
       "      <td>31</td>\n",
       "      <td>46</td>\n",
       "      <td>24</td>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>18</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    SEASON_ID     TEAM_ID TEAM_ABBREVIATION       TEAM_NAME     GAME_ID  \\\n",
       "53      22017  1610612738               BOS  Boston Celtics  0021701171   \n",
       "55      22017  1610612738               BOS  Boston Celtics  0021701140   \n",
       "76      22017  1610612738               BOS  Boston Celtics  0021700798   \n",
       "117     22017  1610612738               BOS  Boston Celtics  0021700188   \n",
       "\n",
       "      GAME_DATE      MATCHUP WL  MIN  PTS     ...      FT_PCT  OREB  DREB  \\\n",
       "53   2018-04-04    BOS @ TOR  L  237   78     ...       0.893     8    35   \n",
       "55   2018-03-31  BOS vs. TOR  W  240  110     ...       0.852     8    33   \n",
       "76   2018-02-06    BOS @ TOR  L  240   91     ...       0.750     9    29   \n",
       "117  2017-11-12  BOS vs. TOR  W  239   95     ...       0.789    15    31   \n",
       "\n",
       "     REB  AST  STL  BLK  TOV  PF  PLUS_MINUS  \n",
       "53    43   10    7    3   16  16       -18.0  \n",
       "55    41   19    6    3    5  23        11.0  \n",
       "76    38   21    3    3   17  19       -20.0  \n",
       "117   46   24    9    2   14  18         1.0  \n",
       "\n",
       "[4 rows x 28 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Subset the games to where MATCHUP contains 'TOR'.\n",
    "raps_games_1718 = games_1718[games_1718.MATCHUP.str.contains('TOR')]\n",
    "raps_games_1718.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Sort by Game Date and Select the Last Row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SEASON_ID                     22017\n",
       "TEAM_ID                  1610612738\n",
       "TEAM_ABBREVIATION               BOS\n",
       "TEAM_NAME            Boston Celtics\n",
       "GAME_ID                  0021701171\n",
       "GAME_DATE                2018-04-04\n",
       "MATCHUP                   BOS @ TOR\n",
       "WL                                L\n",
       "MIN                             237\n",
       "PTS                              78\n",
       "FGM                              25\n",
       "FGA                              75\n",
       "FG_PCT                        0.333\n",
       "FG3M                              3\n",
       "FG3A                             22\n",
       "FG3_PCT                       0.136\n",
       "FTM                              25\n",
       "FTA                              28\n",
       "FT_PCT                        0.893\n",
       "OREB                              8\n",
       "DREB                             35\n",
       "REB                              43\n",
       "AST                              10\n",
       "STL                               7\n",
       "BLK                               3\n",
       "TOV                              16\n",
       "PF                               16\n",
       "PLUS_MINUS                      -18\n",
       "Name: 53, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "last_raps_game = raps_games_1718.sort_values('GAME_DATE').iloc[-1]\n",
    "last_raps_game"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There it is.\n",
    "\n",
    "We can see the game was on April 4th, was in Toronto, and ended in an 18-point Raptors victory.\n",
    "It can be confusing to read this, but the row is all relative to the Celtics (the team we queried).\n",
    "All the stats (points, rebounds, blocks, plus/minus) are theirs.\n",
    "\n",
    "If we wanted stats for both teams (a common use case), we'd need to get *both* rows for this game ID.\n",
    "There are always two, one with stats for each team.\n",
    "So back to the `LeagueGameFinder`!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0021701171'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "game_id = last_raps_game.GAME_ID\n",
    "game_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SEASON_ID</th>\n",
       "      <th>TEAM_ID</th>\n",
       "      <th>TEAM_ABBREVIATION</th>\n",
       "      <th>TEAM_NAME</th>\n",
       "      <th>GAME_ID</th>\n",
       "      <th>GAME_DATE</th>\n",
       "      <th>MATCHUP</th>\n",
       "      <th>WL</th>\n",
       "      <th>MIN</th>\n",
       "      <th>PTS</th>\n",
       "      <th>...</th>\n",
       "      <th>FT_PCT</th>\n",
       "      <th>OREB</th>\n",
       "      <th>DREB</th>\n",
       "      <th>REB</th>\n",
       "      <th>AST</th>\n",
       "      <th>STL</th>\n",
       "      <th>BLK</th>\n",
       "      <th>TOV</th>\n",
       "      <th>PF</th>\n",
       "      <th>PLUS_MINUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1946</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612761</td>\n",
       "      <td>TOR</td>\n",
       "      <td>Toronto Raptors</td>\n",
       "      <td>0021701171</td>\n",
       "      <td>2018-04-04</td>\n",
       "      <td>TOR vs. BOS</td>\n",
       "      <td>W</td>\n",
       "      <td>240</td>\n",
       "      <td>96</td>\n",
       "      <td>...</td>\n",
       "      <td>0.750</td>\n",
       "      <td>12</td>\n",
       "      <td>36</td>\n",
       "      <td>48</td>\n",
       "      <td>23</td>\n",
       "      <td>10</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>25</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1955</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612738</td>\n",
       "      <td>BOS</td>\n",
       "      <td>Boston Celtics</td>\n",
       "      <td>0021701171</td>\n",
       "      <td>2018-04-04</td>\n",
       "      <td>BOS @ TOR</td>\n",
       "      <td>L</td>\n",
       "      <td>237</td>\n",
       "      <td>78</td>\n",
       "      <td>...</td>\n",
       "      <td>0.893</td>\n",
       "      <td>8</td>\n",
       "      <td>35</td>\n",
       "      <td>43</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>-18.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 28 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     SEASON_ID     TEAM_ID TEAM_ABBREVIATION        TEAM_NAME     GAME_ID  \\\n",
       "1946     22017  1610612761               TOR  Toronto Raptors  0021701171   \n",
       "1955     22017  1610612738               BOS   Boston Celtics  0021701171   \n",
       "\n",
       "       GAME_DATE      MATCHUP WL  MIN  PTS     ...      FT_PCT  OREB  DREB  \\\n",
       "1946  2018-04-04  TOR vs. BOS  W  240   96     ...       0.750    12    36   \n",
       "1955  2018-04-04    BOS @ TOR  L  237   78     ...       0.893     8    35   \n",
       "\n",
       "      REB  AST  STL  BLK  TOV  PF  PLUS_MINUS  \n",
       "1946   48   23   10    6   10  25        18.0  \n",
       "1955   43   10    7    3   16  16       -18.0  \n",
       "\n",
       "[2 rows x 28 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get **all** the games so we can filter to an individual GAME_ID\n",
    "result = leaguegamefinder.LeagueGameFinder()\n",
    "all_games = result.get_data_frames()[0]\n",
    "# Find the game_id we want\n",
    "full_game = all_games[all_games.GAME_ID == game_id]\n",
    "full_game"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Two rows, one with the Celtics' stats and one with the Raptors'.\n",
    "You may want to join these these two rows into one, so you have stats for both teams in the same observation.\n",
    "\n",
    "Because this is a common use case, I wrote a function for it.\n",
    "This function will work for larger datasets too (even though we just have one game here);\n",
    "you can run it on any game DataFrames."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SEASON_ID</th>\n",
       "      <th>TEAM_ID_A</th>\n",
       "      <th>TEAM_ABBREVIATION_A</th>\n",
       "      <th>TEAM_NAME_A</th>\n",
       "      <th>GAME_ID</th>\n",
       "      <th>GAME_DATE</th>\n",
       "      <th>MATCHUP_A</th>\n",
       "      <th>WL_A</th>\n",
       "      <th>MIN_A</th>\n",
       "      <th>PTS_A</th>\n",
       "      <th>...</th>\n",
       "      <th>FT_PCT_B</th>\n",
       "      <th>OREB_B</th>\n",
       "      <th>DREB_B</th>\n",
       "      <th>REB_B</th>\n",
       "      <th>AST_B</th>\n",
       "      <th>STL_B</th>\n",
       "      <th>BLK_B</th>\n",
       "      <th>TOV_B</th>\n",
       "      <th>PF_B</th>\n",
       "      <th>PLUS_MINUS_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>22017</td>\n",
       "      <td>1610612761</td>\n",
       "      <td>TOR</td>\n",
       "      <td>Toronto Raptors</td>\n",
       "      <td>0021701171</td>\n",
       "      <td>2018-04-04</td>\n",
       "      <td>TOR vs. BOS</td>\n",
       "      <td>W</td>\n",
       "      <td>240</td>\n",
       "      <td>96</td>\n",
       "      <td>...</td>\n",
       "      <td>0.893</td>\n",
       "      <td>8</td>\n",
       "      <td>35</td>\n",
       "      <td>43</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>16</td>\n",
       "      <td>16</td>\n",
       "      <td>-18.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 53 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  SEASON_ID   TEAM_ID_A TEAM_ABBREVIATION_A      TEAM_NAME_A     GAME_ID  \\\n",
       "1     22017  1610612761                 TOR  Toronto Raptors  0021701171   \n",
       "\n",
       "    GAME_DATE    MATCHUP_A WL_A  MIN_A  PTS_A      ...       FT_PCT_B  OREB_B  \\\n",
       "1  2018-04-04  TOR vs. BOS    W    240     96      ...          0.893       8   \n",
       "\n",
       "   DREB_B  REB_B  AST_B  STL_B  BLK_B  TOV_B  PF_B  PLUS_MINUS_B  \n",
       "1      35     43     10      7      3     16    16         -18.0  \n",
       "\n",
       "[1 rows x 53 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "def combine_team_games(df, keep_method='home'):\n",
    "    '''Combine a TEAM_ID-GAME_ID unique table into rows by game. Slow.\n",
    "\n",
    "        Parameters\n",
    "        ----------\n",
    "        df : Input DataFrame.\n",
    "        keep_method : {'home', 'away', 'winner', 'loser', ``None``}, default 'home'\n",
    "            - 'home' : Keep rows where TEAM_A is the home team.\n",
    "            - 'away' : Keep rows where TEAM_A is the away team.\n",
    "            - 'winner' : Keep rows where TEAM_A is the losing team.\n",
    "            - 'loser' : Keep rows where TEAM_A is the winning team.\n",
    "            - ``None`` : Keep all rows. Will result in an output DataFrame the same\n",
    "                length as the input DataFrame.\n",
    "                \n",
    "        Returns\n",
    "        -------\n",
    "        result : DataFrame\n",
    "    '''\n",
    "    # Join every row to all others with the same game ID.\n",
    "    joined = pd.merge(df, df, suffixes=['_A', '_B'],\n",
    "                      on=['SEASON_ID', 'GAME_ID', 'GAME_DATE'])\n",
    "    # Filter out any row that is joined to itself.\n",
    "    result = joined[joined.TEAM_ID_A != joined.TEAM_ID_B]\n",
    "    # Take action based on the keep_method flag.\n",
    "    if keep_method is None:\n",
    "        # Return all the rows.\n",
    "        pass\n",
    "    elif keep_method.lower() == 'home':\n",
    "        # Keep rows where TEAM_A is the home team.\n",
    "        result = result[result.MATCHUP_A.str.contains(' vs. ')]\n",
    "    elif keep_method.lower() == 'away':\n",
    "        # Keep rows where TEAM_A is the away team.\n",
    "        result = result[result.MATCHUP_A.str.contains(' @ ')]\n",
    "    elif keep_method.lower() == 'winner':\n",
    "        result = result[result.WL_A == 'W']\n",
    "    elif keep_method.lower() == 'loser':\n",
    "        result = result[result.WL_A == 'L']\n",
    "    else:\n",
    "        raise ValueError(f'Invalid keep_method: {keep_method}')\n",
    "    return result\n",
    "    \n",
    "# Combine the game rows into one. By default, the home team will be TEAM_A.\n",
    "game_df = combine_team_games(full_game)\n",
    "game_df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Play-by-play Data for a Given Game\n",
    "With a game ID (which we found above), we can easily fetch play-by-play data for that game."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GAME_ID</th>\n",
       "      <th>EVENTNUM</th>\n",
       "      <th>EVENTMSGTYPE</th>\n",
       "      <th>EVENTMSGACTIONTYPE</th>\n",
       "      <th>PERIOD</th>\n",
       "      <th>WCTIMESTRING</th>\n",
       "      <th>PCTIMESTRING</th>\n",
       "      <th>HOMEDESCRIPTION</th>\n",
       "      <th>NEUTRALDESCRIPTION</th>\n",
       "      <th>VISITORDESCRIPTION</th>\n",
       "      <th>...</th>\n",
       "      <th>PLAYER2_TEAM_CITY</th>\n",
       "      <th>PLAYER2_TEAM_NICKNAME</th>\n",
       "      <th>PLAYER2_TEAM_ABBREVIATION</th>\n",
       "      <th>PERSON3TYPE</th>\n",
       "      <th>PLAYER3_ID</th>\n",
       "      <th>PLAYER3_NAME</th>\n",
       "      <th>PLAYER3_TEAM_ID</th>\n",
       "      <th>PLAYER3_TEAM_CITY</th>\n",
       "      <th>PLAYER3_TEAM_NICKNAME</th>\n",
       "      <th>PLAYER3_TEAM_ABBREVIATION</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0021701171</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>8:11 PM</td>\n",
       "      <td>12:00</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0021701171</td>\n",
       "      <td>4</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>8:11 PM</td>\n",
       "      <td>12:00</td>\n",
       "      <td>Jump Ball Valanciunas vs. Baynes: Tip to Anunoby</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>Boston</td>\n",
       "      <td>Celtics</td>\n",
       "      <td>BOS</td>\n",
       "      <td>4</td>\n",
       "      <td>1628384</td>\n",
       "      <td>OG Anunoby</td>\n",
       "      <td>1.610613e+09</td>\n",
       "      <td>Toronto</td>\n",
       "      <td>Raptors</td>\n",
       "      <td>TOR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0021701171</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>8:11 PM</td>\n",
       "      <td>11:38</td>\n",
       "      <td>MISS DeRozan 21' Jump Shot</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0021701171</td>\n",
       "      <td>8</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>8:11 PM</td>\n",
       "      <td>11:36</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>Tatum REBOUND (Off:0 Def:1)</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0021701171</td>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>86</td>\n",
       "      <td>1</td>\n",
       "      <td>8:12 PM</td>\n",
       "      <td>11:21</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>MISS Horford 12' Turnaround Fadeaway Shot</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>NaN</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 33 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      GAME_ID  EVENTNUM  EVENTMSGTYPE  EVENTMSGACTIONTYPE  PERIOD  \\\n",
       "0  0021701171         2            12                   0       1   \n",
       "1  0021701171         4            10                   0       1   \n",
       "2  0021701171         7             2                   1       1   \n",
       "3  0021701171         8             4                   0       1   \n",
       "4  0021701171         9             2                  86       1   \n",
       "\n",
       "  WCTIMESTRING PCTIMESTRING                                   HOMEDESCRIPTION  \\\n",
       "0      8:11 PM        12:00                                              None   \n",
       "1      8:11 PM        12:00  Jump Ball Valanciunas vs. Baynes: Tip to Anunoby   \n",
       "2      8:11 PM        11:38                        MISS DeRozan 21' Jump Shot   \n",
       "3      8:11 PM        11:36                                              None   \n",
       "4      8:12 PM        11:21                                              None   \n",
       "\n",
       "  NEUTRALDESCRIPTION                         VISITORDESCRIPTION  \\\n",
       "0               None                                       None   \n",
       "1               None                                       None   \n",
       "2               None                                       None   \n",
       "3               None                Tatum REBOUND (Off:0 Def:1)   \n",
       "4               None  MISS Horford 12' Turnaround Fadeaway Shot   \n",
       "\n",
       "             ...             PLAYER2_TEAM_CITY PLAYER2_TEAM_NICKNAME  \\\n",
       "0            ...                          None                  None   \n",
       "1            ...                        Boston               Celtics   \n",
       "2            ...                          None                  None   \n",
       "3            ...                          None                  None   \n",
       "4            ...                          None                  None   \n",
       "\n",
       "   PLAYER2_TEAM_ABBREVIATION  PERSON3TYPE PLAYER3_ID  PLAYER3_NAME  \\\n",
       "0                       None            0          0          None   \n",
       "1                        BOS            4    1628384    OG Anunoby   \n",
       "2                       None            0          0          None   \n",
       "3                       None            0          0          None   \n",
       "4                       None            0          0          None   \n",
       "\n",
       "  PLAYER3_TEAM_ID PLAYER3_TEAM_CITY PLAYER3_TEAM_NICKNAME  \\\n",
       "0             NaN              None                  None   \n",
       "1    1.610613e+09           Toronto               Raptors   \n",
       "2             NaN              None                  None   \n",
       "3             NaN              None                  None   \n",
       "4             NaN              None                  None   \n",
       "\n",
       "   PLAYER3_TEAM_ABBREVIATION  \n",
       "0                       None  \n",
       "1                        TOR  \n",
       "2                       None  \n",
       "3                       None  \n",
       "4                       None  \n",
       "\n",
       "[5 rows x 33 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from nba_api.stats.endpoints import playbyplayv2\n",
    "pbp = playbyplayv2.PlayByPlayV2(game_id)\n",
    "pbp = pbp.get_data_frames()[0]\n",
    "pbp.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "nba",
   "language": "python",
   "name": "nba"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
